package com.sskj.fca.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.fca.http.HttpConfig;
import com.sskj.fca.ui.activity.RegisterActivity;

/**
 * Created by QinKang on 2018/12/28.
 */

public class RegisterPresenter extends BasePresenter<RegisterActivity> {

    /**
     * 获取短信验证码---codeType
     * 1注册 2 重置 3 安全验证 4 订单确认通知(标记付款时) 5 订单处理通知(卖给他时) 6排单成功
     *
     * @param mobile 手机号
     * @return
     */
    public void sendCode(String mobile) {
        httpService.sendCode(mobile, "1")
                .tag(this)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.msg);
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.sendCodeOk();
                        }
                    }

                    @Override
                    public void onError(Response<HttpData> response) {
                        ToastUtil.showShort(response.body().msg);
                        super.onError(response);
                    }
                });
    }

    /**
     * 注册
     *
     * @param mobile   手机号
     * @param opwd     登录密码
     * @param code     验证码
     * @param tjuser   推荐人
     * @param realname 昵称
     */
    public void register(String mobile, String opwd, String code, String tjuser, String realname) {
        httpService.register(mobile, opwd, code, tjuser, realname)
                .tag(this)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.registerSuccess();
                        }
                    }
                });
    }

}
